app.controller('az2', function ($scope, $rootScope, $http, $interval, $compile, $state) {
    //录入基本信息
    $scope.az13 = function () {
        az13.params.caseNum = $scope.installtionCase.caseNum;
        az13.params.productName = $scope.productName;
        $scope.clearItem();
        az13.params.caseId = $scope.caseId;
        az13.params.address = $scope.installtionCase.address;
        localStorage.setItem("sdm-caseNum",$scope.installtionCase.caseNum);
        $state.go(az13.stateName);
    }
    
    $scope.clearItem = function () {
        localStorage.removeItem("sdm-feSignUrl");
        localStorage.removeItem("sdm-customerSignUrl");
        localStorage.removeItem("sdm-ocrUsageInfoPage");
        localStorage.removeItem("sdm-ocrSupplyStatusPage");
        localStorage.removeItem("sdm-ocrConfigPage");
        localStorage.removeItem("sdm-caseNum");
    }
    
	$scope.sixteen = function(type){
        if($scope.installtionCase.status!=5){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "该任务暂不能进行签字"));
            return;
        }
        if(!$scope.ocrUsageInfoPage){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "用量信息页为空，不能进行签字"));
            return;
        }
        if($scope.ocrUsageInfoPage.totalMono==="" || $scope.ocrUsageInfoPage.totalColor==="" || $scope.ocrUsageInfoPage.monochrome===""
        || $scope.ocrUsageInfoPage.accent==="" || $scope.ocrUsageInfoPage.generalOffice==="" || $scope.ocrUsageInfoPage.other===""){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "用量信息页为空，不能进行签字"));
            return;
        }

        sixteen.params.type = type;
        sixteen.params.caseId = $scope.caseId;

        localStorage.setItem("sdm-type",type);
        localStorage.setItem("sdm-caseId",$scope.caseId);
		$state.go(sixteen.stateName);
	}
	
	$scope.fourteen = function(){
		$state.go(fourteen.stateName);
	}

	//升级
	$scope.eight = function(){
	    var caseId = $scope.caseId;
        eight.params.caseId = caseId;
        eight.params.dueDate = $scope.installtionCase.dueDate;
        localStorage.setItem("sdm-caseId",caseId);
		$state.go(eight.stateName);
	}

    //获得数据
    $scope.getOrders = function () {
	    if(!$scope.caseId){
	        return;
        }
		var postData = {};
        getHttp($http, 'installtionCase/get?caseId='+$scope.caseId, postData, function (res) {
            if (res.code === 0 && res.msg == "success") {
                $scope.isOcr = res.isOcr;
                $scope.ocrUsageInfoPage = res.ocrUsageInfoPage;  //用量信息页数据
                $scope.ocrConfigPage = res.ocrConfigPage;  //配置页数据
                $scope.casePhoto = res.casePhoto;      //照片数据
                if($scope.casePhoto){
                    $scope.photourls = JSON.parse($scope.casePhoto.urls);
                }                
                $scope.installtionCase = res.installtionCase;  //任务详情数据和打印机信息

                if($scope.installtionCase.productInfo){
                    //配件信息
                    $scope.installtionCase.accessoryInfo = [];
                    var temp = JSON.parse($scope.installtionCase.productInfo);
                    //产品名称
                    $scope.productName = temp[0].model;

                    //json中第一部分为打印机信息，剩下的是配件信息
                    if(temp.length > 1){
                        for(var i=1;i<temp.length;i++){
                            $scope.installtionCase.accessoryInfo.push(temp[i]);
                        }
                    }
                }

                $scope.ocrStatusReportPage = res.ocrStatusReportPage;  //打印机状态报告数据&耗材状态页

                $scope.customerSignUrl = $scope.installtionCase.customerSignUrl;   //客户签字
                $scope.fesignUrl = $scope.installtionCase.feSignUrl;  //工程师签字


                $scope.$applyAsync();
            } else {
                $rootScope.tipPopups.show(($rootScope.tipMessage = res.msg));
            }
        });
    }

    //显示图片
    $scope.viewerImg = function(index,objectArray){
        // jquery weui 图片浏览器  不能看长图
        if (!objectArray || objectArray.length == 0) return false;
        var images = [];
        for (var i in objectArray) {
            if (objectArray[i])
                images.push(objectArray[i]);
        }
        if (images.length == 0) return false;
        var pb = $.photoBrowser({
            items: images,
            initIndex: index,
            onOpen: function () {
                console.log(this);
            }
        });
        // pb.currentScale = 2;
        pb.open();  //打开
    }


    $scope.transfer = function (item,value) {
	    if(!item){
	        return;
        }
        item = JSON.parse(item);
        return item[0][value];
    }

    $scope.accessoryTransfer = function (item,valueT,index) {
	    if(!item){
	        return;
        }
        item = JSON.parse(item);
        return item[index][value];
    }

    $scope.transferImg = function (json,value) {
        if(!json){
            return;
        }
        var obj = JSON.parse(json);
        return obj[value];
    }
    //初始化
    function init(){
        $scope.photourls = [];  //图片信息

	    $scope.caseId = az2.params.caseId;
	    if(!$scope.caseId){
            $scope.caseId = localStorage.getItem("sdm-caseId");
        }
        $scope.getOrders();

        //获得签名
        // $scope.fesignUrl = localStorage.getItem("sdm-feSignUrl");
        // $scope.customerSignUrl = localStorage.getItem("sdm-customerSignUrl");

    }
    
   init();

    reloadJs();
});